<template>
	<view>
		<image src="../../../客服微信.jpg"></image>
	</view>
</template>

<script>
	import {centerInfo,goodPage,postPage,evaluatePage,createFollow,deleteFollow,createBrowse} from '@/common/http.api.js'
	import config from '@/common/config.js'
	import jwt from '@/utils/jwt.js';
	export default {
		data() {
			return {
				videoPlay: false,
				videoUrl: '',
				memberId:'',
				popupShow:false,
				defAvatar: '',
				statusBarHeight:10,
				isShowNav: false,
				current:'home',
				centerData:{},
				avatar:this.defAvatar,
				cleanFlag:false,
				//加载更多标志
				loadMoreFlag:false,
				isEmpty:false,
				evaluateDataList: [],
				postDataList: [],
				goodDataList: [],
				loadStatus: 'loadmore',
				loadingText: '',
				loadmoreText: '',
				nomoreText: '',
				params: {
					memberId:'',
					pageNo: 1,
					status: 0, //全部
					pageSize: 10,
				},
				homeText:'',
				evaluateText:'',
				dynamicText:'',
				praiseText:'',
				attentionText:'',
				fanText:'',
				allText:'',
				sellText:'',
				soldText:'',
				centerText:'',
				cameText:'',
				emptyText:'',
				locale:'',
				loginactionText:'',
				subscribedText:'',
				unsubscribeText:'',
				dayText:'',
				monthText:'',
				yearText:'',
			};
		},
		//页面的生命周期
		onPageScroll(e) {
			if(e.scrollTop >= 100){
				this.isShowNav = true
			}else {
				this.isShowNav = false
			}
		},
		onShow(){
		  this.refresh();
		  this.locale = this.$i18n.locale;
		},
		async onLoad(e){
		  if(e.id){
			this.memberId = e.id;
			this.params.memberId = e.id;
			this.getMemberInfo();
			this.getGoodPage();
		  }
		  if(jwt.getLogin()){
		  	 this.doCreateBrowse();
		  }
		  await this.$onLaunched;
		  this.initData();
		},
		// 这里myvideo 是你上面命名的id    
		onReady: function () {
		    //this.videoContext = uni.createVideoContext("myvideo", this);    // this这个是实例对象  必传
		},
		methods:{
			refresh(){
				this.homeText = this.$t('center.home.text');
				this.evaluateText = this.$t('center.evaluate.text');
				this.dynamicText = this.$t('center.dynamic.text');
				this.praiseText = this.$t('center.praise.text');
				this.attentionText = this.$t('center.attention.text');
				this.fanText = this.$t('center.fan.text');
				this.allText = this.$t('center.all.text');
				this.sellText = this.$t('center.sell.text');
				this.soldText = this.$t('center.sold.text');
				this.centerText = this.$t('center.center.text');
				this.cameText = this.$t('center.came.text');
				this.emptyText = this.$t('common.empty.text');
				this.loadingText = this.$t('common.loading.text');
				this.loadmoreText = this.$t('common.loadmore.text');
				this.nomoreText = this.$t('common.nomore.text');
				this.loginactionText = this.$t('center.loginaction.text');
				this.subscribedText = this.$t('center.subscribed.text');
				this.unsubscribeText = this.$t('center.unsubscribe.text');
				this.dayText = this.$t('common.day.text');
				this.monthText = this.$t('common.month.text');
				this.yearText = this.$t('common.year.text');
			},
			initData(){
				this.defAvatar = this.$store.state.$appInfo.defaultAvatar;
			},
			doCreateBrowse(){
				createBrowse({categoryId:1,oId:this.memberId}).then(res => {});
			},
			verifyLogin(){
				let that = this;
				let login = jwt.getLogin();
				if(!login){
					this.$refs.uToast.show({
						type: 'error',
						message: that.loginactionText,
						complete() {
							uni.navigateTo({
								url: 'pages/common/public/login_one'
							});
						}
					})
				}
				return login;
			},
			doCreateFollow(){
				let that = this;
				if(this.verifyLogin()){
					createFollow({categoryId:0,merchantId:this.memberId}).then(res => {
						if (res.code === 0) {
							this.centerData.hasFollow = true;
							this.$refs.uToast.show({
								message: that.subscribedText,
								type: 'success',
							})
						} else {
							uni.hideLoading();
							this.$refs.uToast.show({
								message: res.msg,
								type: 'error',
							})
						}
					});
				}
			},
			doDeleteFollow(){
				let that = this;
				if(this.verifyLogin()){
					const authToken = jwt.getAccessToken();
					deleteFollow({params:{id:this.memberId},header: {'Authorization': authToken ? `Bearer ${authToken}` : ''}}).then(res => {
						if (res.code === 0) {
							this.centerData.hasFollow = false;
							this.$refs.uToast.show({
								message: that.unsubscribeText,
								type: 'success',
							})
						} else {
							uni.hideLoading();
							this.$refs.uToast.show({
								message: res.msg,
								type: 'error',
							})
						}
					});
				}
			},
			showVideo(flag){
				this.videoPlay = flag;
			},
			// 触发全屏播放的点击事件
			videoShow(url) {
			  this.videoUrl = url;
			  this.videoPlay = true;  // 显示播放盒子
			},
			reset(){
				this.cleanFlag=false;
				//加载更多标志
				this.loadMoreFlag=false;
				this.isEmpty=false;
				this.evaluateDataList=[];
				this.postDataList=[];
				this.goodDataList=[];
				this.loadStatus='loadmore'
				this.loadingText = this.$t('common.loading.text');
				this.loadmoreText = this.$t('common.loadmore.text');
				this.nomoreText = this.$t('common.nomore.text');
				this.params={
					memberId:this.memberId,
					pageNo: 1,
					status: 0, //全部
					pageSize: 10,
				}
			},
			onPopupShow(data){
				this.popupShow = data;
			},
			onGoodStatusTabClick(status){
				if(this.params.status === status){
					this.cleanFlag = false;
				}else{
					this.cleanFlag = true;
				}
				this.params.status=status;
				this.getGoodPage();
			},
			onGoodClick(item){
				debugger
				uni.navigateTo({
					url: 'pages/common/good/info?id='+item.id
				});
			},
			getEvaluatePage(){
				this.loadStatus = 'loading';
				evaluatePage(this.params).then((res)=>{
					debugger
					uni.stopPullDownRefresh()
					if(res.code === 0){
					  if(res.data.list.length === 0){
						this.isEmpty = true;
						this.loadStatus = 'nomore'
						this.loadMoreFlag = false;
					  }else if (res.data.list.length < 10) {
						this.loadStatus = 'nomore'
						this.loadMoreFlag = false;
					  } else {
						this.params.pageNo++;
						this.loadStatus = 'loading'
						this.loadMoreFlag = true;
					  }
					  if (this.params.pageNo > 1) {
						this.evaluateDataList = this.evaluateDataList.concat(res.data.list);
					  } else {
						this.evaluateDataList = res.data.list;
					  }
					}
				  }).catch(error=>{
					console.error(error)
				  })
			},
			getPostPage(){
				this.loadStatus = 'loading';
				postPage(this.params).then((res)=>{
					debugger
					uni.stopPullDownRefresh()
					if(res.code === 0){
					  if(res.data.list.length === 0){
						this.isEmpty = true;
						this.loadStatus = 'nomore'
						this.loadMoreFlag = false;
					  }else if (res.data.list.length < 10) {
						this.loadStatus = 'nomore'
						this.loadMoreFlag = false;
					  } else {
						this.params.pageNo++;
						this.loadStatus = 'loading'
						this.loadMoreFlag = true;
					  }
					  if (this.params.pageNo > 1) {
						this.postDataList = this.postDataList.concat(res.data.list);
					  } else {
						this.postDataList = res.data.list;
					  }
					}
				  }).catch(error=>{
					console.error(error)
				  })
			},
			getGoodPage(){
				this.loadStatus = 'loading';
				debugger
				if(this.cleanFlag){
					this.goodDataList = [];
					this.$refs.waterfallsFlowRef.refresh()
				}
				goodPage(this.params).then((res)=>{
					uni.stopPullDownRefresh()
					if(res.code === 0){
					  if(res.data.list.length === 0){
						this.isEmpty = true;
						this.loadStatus = 'nomore'
						this.loadMoreFlag = false;
					  }else if (res.data.list.length < 10) {
						this.loadStatus = 'nomore'
						this.loadMoreFlag = false;
					  } else {
						this.params.pageNo++;
						this.loadStatus = 'loading'
						this.loadMoreFlag = true;
					  }
					  if (this.params.pageNo > 1) {
						this.goodDataList = this.goodDataList.concat(res.data.list);
					  } else {
						this.goodDataList = res.data.list;
					  }
					}
				  }).catch(error=>{
					console.error(error)
				  })
			},
			getMemberInfo(){
				const authToken = jwt.getAccessToken();
			  	centerInfo({params:{id:this.params.memberId},header: {'Authorization': authToken ? `Bearer ${authToken}` : ''}}).then(res => {
					if (res.code === 0) {
						this.centerData = res.data;
						this.avatar = this.centerData.avatar?this.centerData.avatar:this.defAvatar;
					} else {
						uni.hideLoading();
						this.$refs.uToast.show({
							message: res.msg,
							type: 'error',
						})
					}
				});
			},
			back(){
				uni.navigateBack({delta: 1});
			},
			tabClick(e){
				this.current = e;
				this.reset();
				if('home'===e){
					this.getGoodPage();
				}else if('evaluate'===e){
					this.getEvaluatePage();
				}else{
					this.getPostPage();
				}
			}
		}
	}
</script>

<style lang="scss">
.goshop-center-back{
	padding:20rpx 20rpx 0 20rpx;
}
.goshop-center-user-action{
	display: flex;
	align-items: center;
}
.goshop-center-user-action-img{
	width: 100rpx;
	height: 40rpx;
}
.goshop-center-user{
	padding: 0 20rpx;
	//background-color: $goshop-color-auxiliary-one;
	.goshop-center-user-center{
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 140rpx;
		//border-bottom: 2px solid $goshop-text-color-four;
		.goshop-center-user-avatar-wrap{
			//flex: 1;
		}
		.goshop-center-user-box{
			flex: 3;
			padding-left: 20rpx;
			.goshop-center-user-box-head{
				display: flex;
				justify-content: flex-start;
				align-items: center;
				.goshop-center-user-name{
					display: flex;
				}
				.goshop-level-box{
					flex: 3;
				}
			}
			.goshop-center-user-box-body{
				display: flex;
				justify-content: space-between;
			}
			.goshop-center-user-box-footer{
				display: flex;
			}
		}
	}
	.goshop-center-user-desc{
		display: flex;
	}
	.goshop-center-user-remark{
		display: flex;
		align-items: center;
		color: $goshop-color-auxiliary-one;
	}
}
.goshop-center-bg{
	//background-image: url(~@/static/imgs/common/avatar.jpg);
	// background-size: 100% 100%;
	// background-position: 50% 50%;
	// background-repeat: no-repeat;
	// filter: blur(3px);
	height: 400rpx;
	background-color: #DCD9D4;
	background-image: linear-gradient(to bottom, rgba(255,255,255,0.50) 0%, rgba(0,0,0,0.50) 100%), radial-gradient(at 50% 0%, rgba(255,255,255,0.10) 0%, rgba(0,0,0,0.50) 50%);
	background-blend-mode: soft-light,screen;
}
.goshop-center-head{
	height: 400rpx;
	position: absolute;
	top: 0;
	right: 0;
	left: 0;
}
.goshop-center-tabs{
	border-radius: 20rpx 20rpx 0 0;
	background-color: $goshop-color-auxiliary-one;
	position: absolute;
	top: 200px;
	left: 0;
	right: 0;
	display: flex;
	justify-content: space-between;
	padding:0 20rpx;
	height: 80rpx;
	.center-tabs-active :after{
		content: '';
		width: auto;
		min-width: 44px;
		height: 2px;
		background: $goshop-color-primary;
		border-radius: 1px;
		display: block;
		margin-top: 1px;
	}
}
.goshop-center-container{
	.goshop-center-navbar{
		//background-color: $goshop-color-auxiliary-one;
	}
	.goshop-center-box{

	}
}
.goshop-center-tabs-home{
	margin-top: 60rpx;
	padding: 20rpx;
	.goshop-center-type{
		display: flex;
		justify-content: flex-start;
		.type-btn{
			//width: 100rpx;
			border-radius: 50rpx;
			border: 2rpx solid $goshop-text-color-three;
			display: flex;
			justify-content: center;
			align-items: center;
			padding:10rpx 20rpx;
		}
		.type-btn-active{
			background-color: $goshop-color-primary;
			color: $goshop-color-auxiliary-one;
		}
	}
}
.goshop-center-tabs-evaluate{
	margin-top: 30rpx;
	padding: 20rpx;
}
.goshop-center-tabs-dynamic{
	margin-top: 30rpx;
	padding: 20rpx;
}
</style>
